package cn.itlaobing.springbootdemo.web.filter;

import cn.itlaobing.springbootdemo.Constants;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AuthenticationInterceptor extends HandlerInterceptorAdapter{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession();
        if(session.getAttribute(Constants.CURRENT_ACCOUNT)==null){
            response.sendRedirect(request.getContextPath()+"/signin");
            return false;
        }
        return true;
    }
}
